<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../VueJs/vue.js"></script>
</head>

<body>

    <div id="root">
        <ul>
            <li v-for="(item,index) in filterPersons" :key="item.id">
                {{item.name}}--{{item.age}}--{{item.sex}}
            </li>
        </ul>
        <input type="text" placeholder="请输入名字" v-model="keyWord">
    </div>
</body>
<script>
    Vue.config.productionTip = false;
    Vue.config.devtools = true;

    const vm = new Vue({
        el: '#root',
        data: {
            persons: [
                { id: '001', name: '马冬梅', age: 18, sex: '女' },
                { id: '002', name: '周冬雨', age: 20, sex: '女' },
                { id: '003', name: '周杰伦', age: 30, sex: '男' },
                { id: '004', name: '最终版', age: 30, sex: '男' },
                { id: '005', name: 'mimi', age: 30, sex: '男' },
            ],
            filterPersons: [],
            keyWord: ''
        },
        watch: {
            keyWord: {
                immediate: true,
                handler: function (newValue, oldValue) {
                    const newPersons = this.persons.filter((item, i) => {
                        return item.name.includes(newValue);
                    });
                    this.filterPersons = newPersons;
                }
            }
        }
    });
</script>

</html>